home *** CD-ROM | disk | FTP | other *** search
- #include <QD3D.h>
- #include <QD3DSet.h>
-
- #include <QD3DIO.h>
- #include <QD3DString.h>
- #include <QD3DGeometry.h>
-
- #include <stdlib.h>
-
- #include "NameAttributeHandler.h"
-
- static TQ3ObjectClass gNameAttributeClass = NULL;
-
- /**********************************************************************************************
- *
- * NAME custom attribute
- *
- **********************************************************************************************/
-
-
- /*
- * Utility function to add a name on an shape object, geometry object, or attribute set
- */
-
- TQ3Status SetName(TQ3Object object, char *name)
- {
- TQ3StringObject string = NULL;
- TQ3AttributeSet set = NULL;
- TQ3Status status = kQ3Success;
-
- if( Q3Object_IsType(object, kQ3SharedTypeShape) == kQ3True ) {
-
- string = Q3CString_New(name);
-
- if( string == NULL) {
- status = kQ3Failure;
- goto cleanExit;
- }
-
- if( Q3Object_IsType(object, kQ3ShapeTypeGeometry) == kQ3True ) {
-
- Q3Geometry_GetAttributeSet(object, &set);
-
- if( set == NULL ) {
- set = Q3AttributeSet_New();
- if( set == NULL ) {
- status = kQ3Failure;
- goto cleanExit;
- }
- Q3Geometry_SetAttributeSet(object, set);
- }
- } else {
- Q3Shape_GetSet(object, &set);
-
- if( set == NULL ) {
- set = Q3Set_New();
- if( set == NULL ) {
- status = kQ3Failure;
- goto cleanExit;
- }
- Q3Shape_SetSet(object, set);
- }
- }
-
- if( Q3Set_Add(set, kElementTypeName, &string) == kQ3Failure ) {
- status = kQ3Failure;
- goto cleanExit;
- }
- } else if( Q3Object_IsType(object, kQ3SharedTypeSet) == kQ3True ) {
- string = Q3CString_New(name);
-
- if( string == NULL) {
- status = kQ3Failure;
- goto cleanExit;
- }
-
- if( Q3AttributeSet_Add(object, kElementTypeName, &string) == kQ3Failure ) {
- status = kQ3Failure;
- goto cleanExit;
- }
- } else
- status = kQ3Failure;
-
- cleanExit:
- if( string )
- Q3Object_Dispose(string);
- if( set )
- Q3Object_Dispose(set);
- return status;
- }
-
- /*
- * Static Functions
- */
-
- static TQ3Status NameAttribute_Traverse(
- TQ3Object unused,
- TQ3StringObject *stringObject,
- TQ3ViewObject view)
- {
- (void) unused;
-
- if (stringObject == NULL || *stringObject == NULL)
- return kQ3Success;
-
- Q3View_SubmitWriteData(view,0,0,0);
-
- if (Q3Object_Submit( *stringObject, view) == kQ3Failure)
- return kQ3Failure;
-
- return kQ3Success;
- }
-
- static TQ3Status NameAttribute_ReadData(
- TQ3SetObject attributeSet,
- TQ3FileObject file)
- {
- TQ3StringObject stringObject;
- TQ3Status status;
-
- stringObject = Q3File_ReadObject(file);
-
- status = Q3Set_Add(attributeSet, kElementTypeName, &stringObject);
-
- if (status == kQ3Failure)
- Q3Object_Dispose(stringObject);
-
- /*
- Note that the string object has a reference count of 1,
- which will be taken care of in the dispose
- */
- return status;
- }
-
- static TQ3Status NameAttribute_CopyAdd(
- TQ3StringObject *src,
- TQ3StringObject *dst)
- {
- *dst = Q3Shared_GetReference(*src);
- if (*dst == NULL)
- return kQ3Failure;
-
- return kQ3Success;
- }
-
- static TQ3Status NameAttribute_CopyReplace(
- TQ3StringObject *src,
- TQ3StringObject *dst)
- {
- TQ3StringObject tempString;
-
- /*
- It is always good form to get a reference first,
- in case src and dst point to the same object
- */
-
- tempString = Q3Shared_GetReference(*src);
- if (tempString == NULL)
- return kQ3Failure;
-
- if( *src )
- Q3Object_Dispose( *src );
-
- *dst = tempString;
-
- return kQ3Success;
- }
-
- static TQ3Status NameAttribute_Delete(
- TQ3StringObject *stringObject)
- {
- if(*stringObject)
- Q3Object_Dispose(*stringObject);
- return kQ3Success;
- }
-
- TQ3Status NameAttribute_Unregister(
- void)
- {
- if ( gNameAttributeClass != NULL )
- return Q3ObjectClass_Unregister(gNameAttributeClass);
-
- return kQ3Failure;
- }
-
- /*
- * NameAttribute_MetaHandler
- */
- static TQ3FunctionPointer NameAttribute_MetaHandler(
- TQ3MethodType methodType)
- {
- switch (methodType)
- {
- case kQ3MethodTypeObjectTraverse:
- return (TQ3FunctionPointer) NameAttribute_Traverse;
- case kQ3MethodTypeObjectReadData:
- return (TQ3FunctionPointer) NameAttribute_ReadData;
- case kQ3MethodTypeElementCopyAdd:
- case kQ3MethodTypeElementCopyGet:
- case kQ3MethodTypeElementCopyDuplicate:
- return (TQ3FunctionPointer) NameAttribute_CopyAdd;
- case kQ3MethodTypeElementCopyReplace:
- return (TQ3FunctionPointer) NameAttribute_CopyReplace;
- case kQ3MethodTypeElementDelete:
- return (TQ3FunctionPointer) NameAttribute_Delete;
- default:
- return (TQ3FunctionPointer) NULL;
- }
- }
-
- /*
- * NameAttribute_Register
- */
- TQ3Status NameAttribute_Register(
- void)
- {
- gNameAttributeClass =
- Q3ElementClass_Register(
- kElementTypeName,
- "NameAttribute",
- sizeof(TQ3StringObject),
- NameAttribute_MetaHandler);
-
- return (gNameAttributeClass == NULL ? kQ3Failure : kQ3Success);
- }
-